package com.jinghang.wayofrich.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.jinghang.wayofrich.R;
import com.jinghang.wayofrich.beans.IndexBank;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

public class IndexGridAdapter extends BaseAdapter {
    private List<IndexBank> gridData;
    private LayoutInflater inflater;

    public IndexGridAdapter(List<IndexBank> gridData, Context context) {
        this.gridData = gridData;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return gridData.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageLoader imageLoader= ImageLoader.getInstance();
        ViewHolderGrid holer = null;
        View view = inflater.inflate(R.layout.fragment_index_bank, null);
        if (holer == null) {
            holer = new ViewHolderGrid();
            holer.name = (TextView) view.findViewById(R.id.index_bankName);
            holer.item_know_grid_img = (ImageView) view.findViewById(R.id.index_bankImg);
            view.setTag(holer);

        } else {
            holer = (ViewHolderGrid) view.getTag();
        }

        holer.name.setText(gridData.get(position).getName());
//            //          加载图片
        imageLoader.displayImage(gridData.get(position).getImgurl(), holer.item_know_grid_img);
        return view;
    }
    //  适配器中的GridView缓存类
    class ViewHolderGrid {
        TextView name;
        ImageView item_know_grid_img;
    }
}
